package com.battle.service.repository.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.battle.pojo.entity.Sirens;
import com.battle.service.mapper.SirensMapper;
import com.battle.service.repository.in.SirensRepository;
import nirvana.core.repository.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.springframework.stereotype.Service;
    import com.battle.pojo.dto.sirens.*;
    import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

/**
* 【描 述】：
* 【环 境】：J2SE
* 【详 细】：
*
*/
@Service
public class SirensRepositoryImpl extends Repository< SirensMapper , Sirens> implements SirensRepository {

private final SirensMapper mapper;

public SirensRepositoryImpl(SirensMapper mapper) {
this.mapper = mapper;
}

    /**
    * 搜索警情
    * @param dto
    * @return
    */
    @Override
    public Page< Sirens > selectSirens(SelectSirensDto dto){

    return mapper.selectSirens(dto);
    }

@Override
public  Map<Long, Sirens> getMap(List<Long> ids){
    Map<Long, Sirens> map = new HashMap<>();

    if (CollectionUtil.isNotEmpty(ids)) {
        List<Sirens> list =listByIds(ids);
        if (CollectionUtil.isNotEmpty(list)) {
        map = list.stream().collect(Collectors.toMap(Sirens::getId, pojo -> pojo));
         }
        }
        return map;
    }


    @Override
    public Sirens getSirensByApiId(String apiId) {
        return mapper.selectOne(new LambdaQueryWrapper<Sirens>()
                .eq(Sirens::getSirensApiId, apiId)
        );
    }
}